#!/usr/bin/env python
#coding: iso-8859-1

"""Documentation for "filename"

Just a small texto node to set a simple score

project -- Rez: The Clone
author -- Edwood Grant
organization -- Binhex Tw. 
version -- 1.00
since -- 8/07/2007 0:57:02
"""

#Panda specific imports for this module
from pandac.PandaModules import * 

#User imports
import globals

from direct.gui.DirectGui import *
from pandac.PandaModules import *

class Score:
	def __init__(self):
		self.modTS = TextureStage("Modulate")
		self.modTS.setMode(TextureStage.MModulate)
		# Creats a texture stage to use for making alpha cut outs.

                #self.fonts = {"silver" : loader.loadFont("'../data/lvl/level1/gui/LuconBlue.egg")}

		self.createLLHUD()
		# Creates the lower left corner of the HUD.

		self.visible = False
		# a boolean variable that let's the HUD know if it is visible
		# or not.

		taskMgr.add(self.updateHUD, "Update HUD")
		# Adds the task that keeps HUD info up to date.
                self.text = TextNode('node name')
                txt = "SCORE: " + str(globals.SCORE)
                self.text.setText(txt)
                self.text.setTextColor(1, 0, 0, 1)
                self.text.setShadow(0.05, 0.05)
                self.text.setShadowColor(0, 0, 0, 1)

                self.textNodePath = aspect2d.attachNewNode(self.text)
                self.textNodePath.setPos(0.90, 0, 0.90)
                self.textNodePath.setScale(0.07)

                self.text2= TextNode('node name')
                self.text2.setText(txt)
                self.text2.setTextColor(1, 0.63, 0.63, 1)
                self.text2.setShadow(0.05, 0.05)
                self.text2.setShadowColor(0, 0, 0, 1)

                self.textNodePath = aspect2d.attachNewNode(self.text2)
                self.textNodePath.setPos(0.80, 0, 0.80)
                self.textNodePath.setScale(0.07)

                self.player = None
                
	def setPlayer(self, player):
		self.player = player
		return


	def createLLHUD(self):
		self.llFrame = DirectFrame(frameSize = (0,.60,0,.45),
			frameColor = (1, 1, 1, 0),
			parent = base.a2dBottomLeft)
		# Creates the frame that will house the lower left portion
		# of the HUD.

		shieldEgg = loader.loadModel("../data/lvl/level1/gui/ShieldBar.egg")
		self.shieldBG = shieldEgg.find("**/BackgroundBar")
		self.shieldBar = shieldEgg.find("**/ShieldBar")
		self.shieldFrame = shieldEgg.find("**/BarFrame")
		self.shieldBG.reparentTo(self.llFrame)
		self.shieldBar.reparentTo(self.shieldBG)
		self.shieldFrame.reparentTo(self.shieldBG)
		self.shieldBG.setPos(.1,0, .225)
		# Loads the three parts of the Shield Bar and places them
		# on the lower left frame.

		speedEgg = loader.loadModel("../data/lvl/level1/gui/SpeedBar.egg")
		self.speedBG = speedEgg.find("**/BackgroundBar")
		self.speedBar = speedEgg.find("**/SpeedBar")
		self.speedFrame = speedEgg.find("**/BarFrame")
		self.speedBG.reparentTo(self.llFrame)
		self.speedBar.reparentTo(self.speedBG)
		self.speedFrame.reparentTo(self.speedBG)
		self.speedBG.setPos(.25,0, .225)
		# Loads the three parts of the Speed Bar and places them
		# on the lower left frame.

		alpha = loader.loadTexture("../data/lvl/level1/gui/BarAlpha.png")
		alpha.setFormat(Texture.FAlpha)
		alpha.setWrapV(Texture.WMClamp)
		# Loads and alpha texture to use as a cut out for the
		# bars.

		self.speedBar.setTexture(self.modTS, alpha)
		self.shieldBar.setTexture(self.modTS, alpha)


		return

	def updateLLHUD(self):
		self.speedBar.setTexOffset(self.modTS, 0,1.0-self.player.light_count)
		self.shieldBar.setTexOffset(self.modTS,	0,1.0-self.player.shot_count/5.0)

		return

	def updateHUD(self, task):
		dt = globalClock.getDt()
		if (dt > .20):
			return task.cont

                self.updateLLHUD()

                txt = "SCORE: " + str(globals.SCORE)
                self.text.setText(txt)
                self.text2.setText(globals.BIGBOSS)

		return task.cont

	def hide(self):
		self.llFrame.hide()
		self.visible = False
		return

	def show(self):
		self.llFrame.show()
		self.visible = True
		return

